// pages/search-city/search-city.js
const http = require("../../models/http")
Page({

  data: {
    value:"",
    arr:[],
    result:[],
    search:""
  },
  onLoad: function (options) {
    http({
      url:"http://192.168.4.18:8000/city",
      success:res=>{
        var arr = Object.keys(res.data.data.cities) 
        this.setData({
          value:res.data.data,
          arr
        })
        // console.log(this.data.value);
      }
    })
  },
  onSearch(event){
    this.setData({
      search:event.detail.trim()
    })
    let result = [];
    let cities = this.data.value.cities;
    for(let res in cities){
      let oneRes = cities[res].filter(item=>{return item.name.includes(this.data.search) || item.spell.includes(this.data.search)})
      result.push(...oneRes)
    }
    this.setData({
      result,
    })
    console.log(this.data.result);
  }
})